home *** CD-ROM | disk | FTP | other *** search
- Path: gryphon.phoenix.net!usenet
- From: brucew@phoenix.net (Bruce Wedding)
- Newsgroups: comp.lang.c
- Subject: Re: C beginner needs your help ASAP
- Date: Tue, 20 Feb 1996 01:25:14 GMT
- Organization: BranPaul Systems
- Message-ID: <4gb7uv$cr2@gryphon.phoenix.net>
- References: <4g862f$p0b@risky.ecs.umass.edu>
- NNTP-Posting-Host: dial147.phoenix.net
- X-Newsreader: Moe's Newsreader
-
-
- >I am a new C programmmer who desperately needs help.
- >I have been digging in the manuals for a way to do this but have still
- >come out empty handed. Here is the problem: I want to open files in a while
- >loop with different filenames. data0,data1,data2,data3, .. data1000 , ...
- >I need to increment an integer each time around then convert it to a string
- >and then somehow use strcat to combine the "data" with the integer string.
- >After that use fopen(filename, "a");
-
- I'm guessing you have an OS that allows you to open 1000 files?
-
- FILE *fp[1000];
- char buf[80];
-
- for ( i =0; i < 1000; i++)
- {
- sprintf(buf, "data%d", i);
- fp[i] = fopen(buf, "w");
- if (fp[i] == NULL)
- /* error message */
- }
-
- That should do it.
-
- Bruce D. Wedding Have Compiler, Will Travel!
- Perspicacious Programming Performed Promptly
- Katy, Texas, USA, Planet Earth, Milkyway Galaxy, Known Universe
-
-